﻿using System;

namespace Kiva7.ViewModels
{
    public class LoanMonthTotals : IComparable<LoanMonthTotals>
    {
        public LoanMonthTotals()
        {
        }

        public LoanMonthTotals(LoanMonthTotals totals)
        {
            Year = totals.Year;
            Month = totals.Month;
            Count = totals.Count;
            CountDefaulted = totals.CountDefaulted;
            CountPaid = totals.CountPaid;
            CountRepaying = totals.CountRepaying;
        }

        public void Addition(LoanMonthTotals totals)
        {
            Year = totals.Year;
            Month = totals.Month;
            Count += totals.Count;
            CountDefaulted += totals.CountDefaulted;
            CountPaid += totals.CountPaid;
            CountRepaying += totals.CountRepaying;
        }

        public void Clear()
        {
            Count = 0;
            CountDefaulted = 0;
            CountPaid = 0;
            CountRepaying = 0;
        }

        public string Label
        {
            get
            {
                DateTime t = new DateTime(Year, Month, 1);
                return t.ToString("MMM yy");
            }
        }

        public int Year { get; set; }
        public int Month { get; set; }

        public int Count { get; set; }
        public int CountRepaying { get; set; }
        public int CountPaid { get; set; }
        public int CountDefaulted { get; set; }

        public int CompareTo(LoanMonthTotals other)
        {
            int i = Year.CompareTo(other.Year);
            if (i != 0)
            {
                return i;
            }
            return Month.CompareTo(other.Month);
        }
    }
}
